<script setup lang="ts">
import { RouterView, useRoute } from 'vue-router'
import TheHeader from './components/layout/TheHeader.vue'
import TheFooter from './components/layout/TheFooter.vue'
import { useI18n } from 'vue-i18n'
import { watch } from 'vue'

const { t, locale } = useI18n()
const route = useRoute()

// 更新页面标题
const updateTitle = () => {
  const titleKey = route.meta.title || 'home'
  document.title = `${t(`nav.${titleKey}`)} - Your Ruan`
}

// 监听路由变化
watch(() => route.path, updateTitle)

// 监听语言变化
watch(() => locale.value, updateTitle)

// 初始化标题
updateTitle()
</script>

<template>
  <div class="app">
    <TheHeader />

    <main class="main-content">
      <RouterView v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </RouterView>
    </main>

    <TheFooter />
  </div>
</template>

<style>
/* 重置和基础样式 */
html {
  box-sizing: border-box;
  font-size: 16px;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--el-font-family);
  color: var(--el-text-color-primary);
  background-color: var(--el-bg-color);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 应用布局 */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  padding-top: 60px; /* 与header高度相同 */
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding-left: 20px;
  padding-right: 20px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  html {
    font-size: 14px;
  }

  .main-content {
    padding-left: 15px;
    padding-right: 15px;
  }
}

/* 过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 滚动条美化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--el-bg-color-page);
}

::-webkit-scrollbar-thumb {
  background: var(--el-border-color-darker);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--el-text-color-secondary);
}
</style>
